package com.ruoyi.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;

import com.ruoyi.domain.Student;
import com.ruoyi.domain.StudentCourse;
import com.ruoyi.domain.StudentEvaluation;
import com.ruoyi.service.IStudentEvaluationService;
import com.ruoyi.service.IStudentService;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;

import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 学生信息  Controller
 *
 * @author ruoyi
 * @date 2024-04-22
 */
@RestController
@RequestMapping("/student")
public class StudentController extends BaseController {
    @Autowired
    private IStudentService studentService;
    @Autowired
    private IStudentEvaluationService studentEvaluationService;

    /**
     * 查询【请填写功能名称】列表
     */

    @GetMapping("/list")
    public TableDataInfo list(Student student) {
        startPage();
        List<Student> list = studentService.selectStudentList(student);
        return getDataTable(list);
    }

    @GetMapping("/getStudentRate")
    public AjaxResult getStudentRate(@RequestParam(value = "studentId", required = false) Long studentId, @RequestParam(value = "name", required = false) String studentName, @RequestParam(value = "major", required = false) String major) {
        startPage();
        List<Student> students = studentEvaluationService.getAllStudentRate(studentId,studentName,major);
        return AjaxResult.success(getDataTable(students));
    }
    @GetMapping("/getStudentRate/{studentId}/{teachId}")
    public AjaxResult getStudentRate(@PathVariable("studentId")Long studentId,@PathVariable("teachId")Long teachId) {
        startPage();
        StudentEvaluation studentEvaluation = studentEvaluationService.getStudentRate(studentId,teachId);
        return AjaxResult.success(studentEvaluation);
    }
    @PostMapping("/rateStudent")
    public AjaxResult getStudentRate(@RequestBody StudentEvaluation studentEvaluation) {
        studentEvaluationService.insertStudentEvaluation(studentEvaluation);
        return AjaxResult.success();
    }


    @GetMapping("/getStudentScore/{student_Id}")
    public AjaxResult getStudentScore(@PathVariable("student_Id") String studentId, @RequestParam(value = "courseName", required = false) String courseName, @RequestParam(value = "teacherName", required = false) String teacherName) {
        startPage();
        List<StudentCourse> studentCourses = studentService.getStudentScore(studentId, courseName, teacherName);
        TableDataInfo dataTable = getDataTable(studentCourses);
        return AjaxResult.success(dataTable);
    }

    /**
     * 导出【请填写功能名称】列表
     */

    @Log(title = "【请填写功能名称】", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, Student student) {
        List<Student> list = studentService.selectStudentList(student);
        ExcelUtil<Student> util = new ExcelUtil<Student>(Student.class);
        util.exportExcel(response, list, "【请填写功能名称】数据");
    }

    /**
     * 获取【请填写功能名称】详细信息
     */

    @GetMapping(value = "/{studentId}")
    public AjaxResult getInfo(@PathVariable("studentId") Long studentId) {
        return success(studentService.selectStudentByStudentId(studentId));
    }

    /**
     * 新增【请填写功能名称】
     */

    @Log(title = "【请填写功能名称】", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody Student student) {
        return toAjax(studentService.insertStudent(student));
    }

    /**
     * 修改【请填写功能名称】
     */

    @Log(title = "【请填写功能名称】", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody Student student) {
        return toAjax(studentService.updateStudent(student));
    }

    /**
     * 删除【请填写功能名称】
     */


    @Log(title = "【请填写功能名称】", businessType = BusinessType.DELETE)
    @DeleteMapping("/{studentIds}")
    public AjaxResult remove(@PathVariable Long[] studentIds) {
        return toAjax(studentService.deleteStudentByStudentIds(studentIds));
    }
}
